﻿#pragma once

template<std::size_t Size>
struct ZNumber {
  // 内部数据位数为Size个uint8_t
  uint8_t data[Size];

  ZNumber() {
    // 初始化数据为0
    memset(data, 0, Size);
  }

  // 转换到 int16_t
  int16_t toInt16() const {
    int16_t tempV{0};
    std::reverse_copy(data, data + Size, reinterpret_cast<uint8_t *>(&tempV));
    return tempV;
  }

  // 转换到 uint16_t
  uint16_t toUInt16() const {
    uint16_t tempV{0};
    std::reverse_copy(data, data + Size, reinterpret_cast<uint8_t *>(&tempV));
    return tempV;
  }

  // 转换到 int32_t
  int32_t toInt32() const {
    int32_t tempV{0};
    std::reverse_copy(data, data + Size, reinterpret_cast<uint8_t *>(&tempV));
    return tempV;
  }

  // 转换到 uint32_t
  uint32_t toUInt32() const {
    uint32_t tempV{0};
    std::reverse_copy(data, data + Size, reinterpret_cast<uint8_t *>(&tempV));
    return tempV;
  }

  // 转换到 int64_t
  int64_t toInt64() const {
    int64_t tempV{0};
    std::reverse_copy(data, data + Size, reinterpret_cast<uint8_t *>(&tempV));
    return tempV;
  }

  // 转换到 uint64_t
  uint64_t toUInt64() const {
    uint64_t tempV{0};
    std::reverse_copy(data, data + Size, reinterpret_cast<uint8_t *>(&tempV));
    return tempV;
  }
};